Find all flights that:
Had an arrival delay of two or more hours
filter(flights, arr_delay >= 120)
Flew to Houston (IAH or HOU)
filter(flights, dest %in% c("IAH", "HOU"))
Were operated by United, American, or Delta
filter(flights, carrier %in% c("AA", "DL", "UA"))
Departed in summer (July, August, and September)
filter(flights, month %in% 7:9)
Arrived more than two hours late, but didn’t leave late
filter(flights, arr_delay > 120, dep_delay <= 0)
Were delayed by at least an hour, but made up over 30 minutes in flight
# For example, if dep_delay is 10 minutes late then arr_delay should be
# 10 mins lates. 10 - 10 = 0, so air time was on time.
# If dep_delay is 10 minutes late but arr_delay is -20 minutes earlier, then
# arr_delay SHOULD'VE been 10 but instead is -20 (because of 30 catch up), so
# 10 - (-20) = 30.
filter(flights, dep_delay >= 60, (dep_delay - arr_delay > 30))
Departed between midnight and 6am (inclusive)
filter(flights, dep_time >= 2400 | dep_time <= 600)